package chatAI

import (
	"context"
	"user_srv/userclient"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateSessionLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCreateSessionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateSessionLogic {
	return &CreateSessionLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CreateSessionLogic) CreateSession(req *types.CreateSessionReq) (resp *types.Response, err error) {
	session, err := l.svcCtx.UserRpc.CreateSession(l.ctx, &userclient.CreateSessionRequest{
		Title: req.Title,
	})
	if err != nil {
		return &types.Response{Code: 400, Message: err.Error()}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "创建会话成功",
		Data: &types.CreateSessionResp{
			SessionId: session.SessionId,
		},
	}, nil
}
